package com.solidit.cassandra.controller.persistance.util;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;

public class CassandraConectionManager {
	private Cluster cluster;
	
	public CassandraConectionManager(String node){
		 cluster = Cluster.builder()
		         .addContactPoint(node).build();
		 this.connect();
		 
	}
	public Session getSession(){
		return cluster.connect();
	} 
	public Metadata getMetadata(){
		
		return cluster.getMetadata();
	} 
	
	public void connect() {
		
		   Metadata metadata = cluster.getMetadata();
		   System.out.printf("Conectado al cluster: %s\n", 
		         metadata.getClusterName());
		   for ( Host host : metadata.getAllHosts() ) {
		      System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n",
		         host.getDatacenter(), host.getAddress(), host.getRack());
		   }
		}
	
	

}
